####################################################################################
## 1、合并seg
## https://www.jianshu.com/p/5de9922e6b8b
## https://www.bioconductor.org/packages/devel/bioc/vignettes/TitanCNA/inst/doc/TitanCNA.pdf
echo -e "Sample\tChromosome\tStart Position\tEnd Position\tNum markers\tSeg.CN" \
> ${Titan_path}/gistci2.input.tsv

for sample in ` cat ${config_path}/tumor_normal.class.MSS_MSI.list | grep -v Normal | grep -v IM- | sort -u | tr '\t' ',' | sed 's/ //g' ` 
do

Tumor=`echo $sample  | awk -F, '{print $3}'`
Normal=`echo $sample  | awk -F, '{print $2}'`

cat ${Titan_path}/FinalModel/${Tumor}_${Normal}.seg | grep -v Sample | \
awk -F'\t' '{OFS="\t"}{print $1,$2,$3,$4,$7,$9}' |\
awk -F"\t" '{if($2!~"X" && $2!~"Y") print}' \
>> ${Titan_path}/gistci2.input.tsv
done

####################################################################################
## 2、run
basedir=${GisticOut_path}
mkdir -p ${basedir}
segfile=${Titan_path}/gistci2.input.tsv
refgenefile=${GISTIC}/refgenefiles/hg19.mat

#cd ${GISTIC}/
#${GISTIC}/gistic2 -b $basedir -seg $segfile -refgene $refgenefile \
#-genegistic 1 -smallmem 1 -broad 1 -brlen 0.5 -conf 0.90 -armpeel 1 -savegene 1 -gcm extreme
udocker run -v /public/:/public/ gistic -b $basedir -seg $segfile -refgene $refgenefile \
-genegistic 1 -smallmem 1 -broad 1 -brlen 0.5 -conf 0.99 -armpeel 1 -savegene 1 -gcm extreme